<?php

namespace Run;

class Base extends \Lib\Core\Business {

    protected  function error($msg, $data, $code) {
        $arr = array(
            'msg' => $msg,
            'data' => $data,
        );
        $json = json_encode($arr);
        $this->throwException($json, $code);
    }

    protected function addErrorInfo($e) {
        $json = $e->getMessage();
        $arr = json_decode($json, true);
        $msg = $arr['msg'];
        $data = $arr['data'];
        if (is_array($data)) {
            $data = json_encode($data);
        }
        $code = $e->getCode();
        $data = array(
            'Data' => $data,
            'Msg' => $msg,
            'Code' => $code,
            'CreateTime' => time(),
        );
        \Data\CrawlError::instance()->add($data);
    }

}